<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class TagClassRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules(\Illuminate\Http\Request $request)
    {
        return [
            'name'              => 'required|max:64|regex:/^[a-zA-Z0-9~@#%_]{1,16}$/i|unique:tags,name,'.$request->get('id'),
            'title'              => 'required|max:64',
            'description'       => 'max:255',
            'sort'               => 'max:255|numeric',
        ];
    }

    public function messages()
    {
        return [
            'name.required'   => '请填写标识名',
            'name.max'        => '标识名字符不得多于64',
            'name.unique' => '标识名不能重复',
            'name.regex' => '标识名只能为数字和字母',

            'title.required' => '请填写展示名',
            'title.max'      => '展示名字符不得多于64',

            'description.max'       => '介绍字符不能大于255',

            'sort.max'         => '排序最多255个数字',
            'sort.numeric'         => '排序必须是数字',
        ];
    }
}
